﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iLangl.Model;
using iLangl.LanguageWire.DAL.LanguageWireDAL;

namespace iLangl.LanguageWire.Managers
{
	public class SettingsManager : BaseManager
	{
		#region Singelton Pattern
		private SettingsManager()
		{
		}

		private static SettingsManager instance;
		private static object mutex = new object();
		/// <summary>
		/// The instance of the SettingsManager.
		/// </summary>
		public static SettingsManager Instance
		{
			get
			{
				if (instance == null)
				{
					lock (mutex)
					{
						if (instance == null)
						{
							instance = new SettingsManager();
						}
					}
				}
				return instance;
			}
		}
		#endregion

		public Contact GetDefaultContact()
		{
			Contact contact = new Contact();
			contact.Id = LWCompanyInfoConfiguration.Instance.ContactId;

			contact.Email = LWCompanyInfoConfiguration.Instance.ContactEmail;
			contact.FirstName = LWCompanyInfoConfiguration.Instance.ContactFirstName;
			contact.LastName = LWCompanyInfoConfiguration.Instance.ContactLastName;
			contact.Phone = LWCompanyInfoConfiguration.Instance.ContactPhone;
			contact.Title = LWCompanyInfoConfiguration.Instance.ContactTitle;
			contact.TPIdentity = "1";

			contact.Company = DALFacadeLW.Instance.CompanyDAL.GetLWCompanyInfo();
			return contact;
		}


		public IList<Language> GetLanguages()
		{
			return DALFacadeLWAPI.SettingsDAL.ReadLanguages();
		}

		public IList<WorkArea> GetWorkAreas()
		{
			return DALFacadeLWAPI.SettingsDAL.ReadWorkAreas();
		}

		public SettingsFromTP GetSettings()
		{
			SettingsFromTP settings = new SettingsFromTP();
			settings.WorkAreas = DALFacadeLWAPI.SettingsDAL.ReadWorkAreas();
			settings.Languages = DALFacadeLWAPI.SettingsDAL.ReadLanguages();
			settings.Products = ProductManager.Instance.GetProducts();
			return settings;
		}
	}
}
